#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/sem.h>
#include <assert.h>
#include <stdio.h>

#define BUFSIZE 1024

int main() {
    int fd[2];
    int sock = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
 //   printf("sock = %d\n", sock);
    int status;
    pid_t pid = fork();
    if (pid == 0) {
        // 子进程
        char str[] = "hello";
        char buf[BUFSIZE];
        write(fd[1], str, sizeof str);
        sleep(1);
        read(fd[1], buf, sizeof buf);
        puts(buf);
    } else {
        // 父进程
        char str[] = "world";
        char buf[BUFSIZE];
        write(fd[0], str, sizeof str);
        read(fd[0], buf, BUFSIZE);
        puts(buf);
        wait(&status);
    }
    return 0;
}